<?php

namespace app\api\controller\xiservice;


use app\common\controller\xiservice\XiserviceApi;
use app\common\model\xiservice\OrderContact;

/**
 * 合同接口
 */
class Contact extends XiserviceApi
{

    protected $noNeedLogin = [];
    protected $noNeedRight = ['*'];

    protected $model = null;

    /**
     * 合同列表
     * @param int page 页码
     * @param int type 当前身份类型,1=雇主,2=师傅
     */
    public function lists()
    {
        $uid = $this->auth->id;
        $type = $this->request->param('type/d', 1);

        $lists = OrderContact::field('id,order_no,name,createtime')
            ->where(function ($query) use ($type, $uid) {
                if ($type == 2) {
                    $query->where('worker_id', $uid);
                } else {
                    $query->where('user_id', $uid);
                }
            })
            ->where('status', 1)
            ->order('id', 'desc')
            ->paginate();

        $this->success('ok', $lists);
    }

    /**
     * 合同详情
     * @param int id 合同单子ID标识
     * @param int type 当前身份类型,1=雇主,2=师傅
     */
    public function detail()
    {
        $id = $this->request->param('id/d');
        $uid = $this->auth->id;
        $type = $this->request->param('type/d', 1);

        $info = OrderContact::field('id,order_no,name,content,createtime')
            ->where(function ($query) use ($type, $uid) {
                if ($type == 2) {
                    $query->where('worker_id', $uid);
                } else {
                    $query->where('user_id', $uid);
                }
            })
            ->where('status', 1)
            ->find();
        $this->success('ok', $info);
    }

}
